package com.mchat.communication.process.message.impl;

import com.mchat.common.dto.bo.OnlineUser;
import com.mchat.communication.process.message.MessageProcessor;
import com.mchat.communication.protocol.IMMessage;
import com.mchat.communication.service.OnlineUserService;
import io.netty.channel.Channel;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class TextMsgProcessor implements MessageProcessor {
    @Resource
    private OnlineUserService onlineUserService;

    @Override
    public void process(Channel client, IMMessage message) {
        IMMessage copyMessage = IMMessage.copyMessage(message);
        OnlineUser user = onlineUserService.getUserByName(message.getSender());
        onlineUserService.sendMessage(user, copyMessage);
    }
}
